perm filename TALK10.PAL[PNT,HE]8 blob sn#557427 filedate 1981-01-19 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	.INSRT	ELFDEF.[PNT,HE]
C00007 00003		server,srvsts,pntexecute
C00014 00004	PNTINIT:
C00018 ENDMK
C⊗;
.INSRT	ELFDEF.[PNT,HE]

STATUS:	.WORD 0	;current status of POINTY in 11
;	server,srvsts,pntexecute

CODE
PNTEXECUTE:
COMMENT	⊗ initializes the buffers and executes the pcode
	⊗

	MOV INTBUF,INTPTR	; beginning of integer buffer
	MOV FPBUF,FPPTR		; beginning of fp buffer
;	MOV #PNTYIN,R4		; R4←POINTY interpreter PDB
;	MOV PDBR4(R4),R4	; R4←POINTY interpreter ISB
	MOV PCDBUF,IPC(R4)	; beginning of pcode buffer

	CMP PCDBEG,PCDBUF	; check if new program or same program
	BNE 1$			; same , so dont reinitialize the environment
	MOV #MAININ,R0		; R0←main interpreter PDB
	MOV PDBR4(R0),R0;	; R0←ISB OF MAIN INTERPRETER
	MOV ENV(R0),ENV(R4)
	MOV LEV(R0),LEV(R4)
; ***
	MOV ENV(R4),R0  	; save environment
	MOV R0,SENV
	MOV LVARS(R0),SLVARS	; save LVARS
; ***
	MOV STKBAS(R4),SBOT	; save value of stack bottom
	MOV STKBAS(R4),R3	; make sure we have a good stack pointer
	ADD #2*INSTSZ,R3	;R3 ← LOC[top of new stack] (INSTSZ is in bytes)
	MOV R3,STTOP		; save value of the top of stack
; ****				; newly added
;1$:	JSR PC,NOTICE		; make sure read arm if necessary
1$:	NOP			; NOTICE DISAPPEARED  BUT CODE FOR NOTICE
				; WAS PUSH <AC,BC,CC>
				; POP <CC,BC,AC>
				; RTS PC
;****
;	MOV RF,-(SP)		; Save RF
;	MOV SP,RF
	MOV SPSAV,-(SP)
	MOV SP,SPSAV
	JSR PC,PINTERP		; go do the interpreting after initialising
;****				; we will return here only from pdone
	MOV INTPTR,INTSIZ	; compute the integer buffer size
	SUB INTBUF,INTSIZ
	ASR INTSIZ
	MOV FPPTR,FPSIZ		; compute the fp buffer size
	SUB FPBUF,FPSIZ		; by getting difference and dividing by 4
	ASR FPSIZ
	ASR FPSIZ
	RTS PC

PINTERP:PUSH <SBOT,STTOP>	; push bottom and top of stack value
	JMP INT1		; and jump into interp

;	routine to let 10 know we are awake
DATA
STPDB:	PDBLK	3,100,F	; set up pbd for process to tell 10 we are alive
CODE

SRVSTS:	MOV STATUS,NOTB11
	TST ALLIVE	; check if AL is still alive
	BNE 1$		; AL is still alive
	DISMIS		; AL is done
1$:	SLEEP	#20
	BR SRVSTS

DATA
PNTYIN::PDBLK 2,150,F	;Makes a process descriptor pointy
SPSAV:	.WORD	0
SBOT:	.WORD	0
STTOP:	.WORD	0
SLVARS: .WORD	0
SENV:	.WORD	0
NOTVL:	0
CODE

SERVER:	MOV NOTB10,NOTVL ;get value of notb10
	CMP NOTVL,#LISTEN	;is he telling us to listen
	BNE 1$
	MOV #LISTNING,STATUS	;say we are ready to listen
	MOV STATUS,NOTB11
	BR  10$
1$:	CMP NOTVL,#WORK		;is he telling us to work?
	BNE 2$
	MOV #WORKING,STATUS
	MOV STATUS,NOTB11	;we will tell him we are working
; *****				;just added
;	MOV #PNTYIN,SP
;	MOV USKMAX(SP),SP	; make sure we get a good stack pointer
; *****
	JSR PC,PNTEXECUTE	;action
	MOV #DONEWORKING,STATUS ;finished working, tell him that
	MOV STATUS,NOTB11
	BR  10$
2$:	CMP NOTVL,#GOSLEEP	;is he telling us he doesnt need us anymore
	BNE 3$
	MOV #AWAKE,STATUS	;tell him we are available
	MOV STATUS,NOTB11
	BR 10$
3$:	CMP NOTVL,#SAVE		; is he telling us he wants to save state?
	BNE 4$
	CLR ALLIVE		; simulate end of AL process to kill display, etc
	SLEEP	#3000.		; let other processes go to sleep
	EVWAIT	CSLEVT		; wait for console to be available
	SLEEP	#1000.		; give other processes a chance to stop
	MOV #SAVED,NOTB11	; say we have saved everything
	SUSPND			; jump to the KERNAL and suspend everything
				; yawn!! we are awake again
	EVSIG	CSLEVT		; release the console
	JSR PC,VALINI		; reinitialize VAL
	JSR PC,INIARM		; reinitialize the arm
	MOV #1,ALLIVE		; let everyone know that AL is alive again
	JSR PC,UPDINIT		; resume updating
	SCHEDU #STPDB,#SRVSTS,#USRDM,#2	;schedule srvsts
	MOV #AWAKE,STATUS
	MOV STATUS,NOTB11
4$:
10$:	CLR NOTB10
	TST ALLIVE		;TEST IF AL PROGRAM FINISHED
	BNE 11$
	DISMIS			;yes, AL program is done, go away
11$:	SLEEP #500		;rest for a little while
	BR  SERVER		;go find out if there is any more mail
; ******			; code to abort pointy
PNTABT: MOV #GAVEUP,STATUS
	MOV STATUS,NOTB11
	BR  SERVER
PNTINIT:
COMMENT	⊗ initialize every thing ⊗
;	MOV #IBUFF,INTBUF	;store starting address as buffer of integers
	MOV #IBUFFSIZ,R0	; get it from free storage instead
	JSR PC,GTFREE
	MOV R0,INTBUF
	MOV #FBUFF,FPBUF	;starting address of FP buffer
;	MOV #PBUFF,PCDBUF	;starting address for pcode buffer
	MOV #PBUFFSIZ,R0	;get it from free storage
	JSR PC,GTFREE
	MOV R0,PCDBUF
	MOV R0,PCDPTR
	MOV R0,PCDBEG		; save value of beginning of pcode buffer
	MOV #AWAKE,STATUS	;tell 10 we are awake
	SCHEDU #STPDB,#SRVSTS,#USRDM,#8.;schedule srvsts
	CLR NOTB11
	CLR NOTB10
;	MOV #1,ALLIVE		;Indicate that the AL interpreter is alive
	MOV #ISBS,R0		;R0 ← Size (in words) of an interpreter status block
	JSR PC,GTFREE		;R0 ← LOC[new interpreter status block]
	MOV R0,-(SP)		;Save LOC[new interpreter status block]
	MOV #INSTSZ,R0		;R0 ← Size needed for an interpreter stack
	JSR PC,GTFREE		;R0 ← LOC[new interpreter stack]
	MOV (SP)+,R1		;R1 ← LOC[new interpreter status block]
	MOV R0,STKBAS(R1)	;Store away new stack base
	ADD #2*INSTSZ,R0	;R0 ← LOC[top of new stack] (INSTSZ is in bytes)
	MOV #PNTYIN,R2		;R2 ← LOC[POINTY process descriptor]
	BIS #UGRSAV+USKSAV,PDBSTA(R2)	;Use saved registers so we can set things up
	MOV R0,PDBR3(R2)	;Store away new interp stack pointer (reg 3)
	MOV R2,PDB(R1)		;Store away LOC[PDB] in new ISB
	MOV R1,PDBR4(R2)	;Store away LOC[ISB] in reg 4 of PDB
	MOV USKMAX(R2),USKP(R2)	;Make sure we have a good stack pointer
	EVWAIT INTEVT		;Interlock sensitive operation, GC needs this
	MOV #NXTINT+ISTBLK,R0	;Link into the interpreter list.
	MOV (R0),NXTINT(R1)
	MOV R1,(R0)
	EVSIG INTEVT		;End of interlock
	SCHEDU R2,#SERVER,#USRDM,#2 ;Cause the new process to be started, suspended
	RTS PC


DATA
PCDBEG:	.WORD	0		; pcode beginning address
;IBUFF:	.BLKW	IBUFFSIZ	; integer buffer
FBUFF:	.BLKW	FBUFFSIZ	; real buffer
;PBUFF:	.BLKW	PBUFFSIZ	; pcode buffer
CODE